//
//  ViewController.swift
//  Core note
//
//  Created by Mac  on 2017/9/15.
//  Copyright © 2017年 Mac . All rights reserved.
//

import UIKit
import CoreData
class ViewController: UIViewController {
    var  contex:NSManagedObjectContext!
    var  entity:NSEntityDescription!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print(NSHomeDirectory())
        contex = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
        entity = NSEntityDescription.entity(forEntityName: "Users", in:  contex)
        let p1 = NSManagedObject(entity: entity, insertInto: contex)
 
       p1.setValue( "yuanbo", forKey: "name")
        p1.setValue(18, forKey: "age")
        p1.setValue("15110100109", forKey: "num")
   


        do{
            try contex.save()
            print("saved")
            
        }
        catch{
            print("error")
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

